package com.company.alibaba;

import java.util.Arrays;
import java.util.Scanner;

public class Main1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] coin = new int[n];
        for(int i = 0;i < n;i++){
            coin[i] = sc.nextInt();
        }
        int[][] houses = new int[m][2];
        for(int i = 0;i < m;i++){
            // 舒适度
            houses[i][0] = sc.nextInt();
            // 价格
            houses[i][1] = sc.nextInt();
        }

        int res = getBiggestConfortable(n,coin,m,houses);
        System.out.println(res);

    }

    private static int getBiggestConfortable(int n, int[] coin, int m, int[][] houses) {
        Arrays.sort(coin);
        // 先按照价格排序，再按照舒适度排序
        Arrays.sort(houses,(a,b) ->{
            if(a[1] != b[1]){
                return  a[1] - b[1];
            }else{
                return a[0] - b[0];
            }
        });

        boolean[] hasUsed = new boolean[m];

        // 按照从高到低排序
        int res = 0;
        for(int i = n - 1;i >= 0;i--){
            int temp_coin = coin[i];
            int start = 0;
            while (start < m && houses[start][1] <= temp_coin ){
                start++;
            }
            int left = start - 1;

            if(left < m){
                int temp_maxConf = Integer.MIN_VALUE;
                int index = left ;
                for(int l = left ;l >=  0;l--){

                    if(!hasUsed[l] && temp_maxConf < houses[l][0]){
                        temp_maxConf = houses[l][0];
                        index = l;
                    }
                }
                // 找到最大的并标记已使用过
                if(temp_maxConf != Integer.MIN_VALUE){
                    res += temp_maxConf;
                    hasUsed[index] = true;
                }

            }

        }

        return res;


    }
}
